<template>
  <div>
    <el-dialog
      title="复用指标"
      :visible.sync="dialogVisible"
      width="80%"
      :close-on-click-modal="false"
      append-to-body
    >
      <div class="boxsty zhiBiao">
        <el-col :span="24">
          <el-form
            :inline="true"
            :model="dataForm"
            @keyup.enter.native="getDataList()"
            class="form-inline"
          >
            <el-form-item label="发起名称">
              <el-input
                v-model="dataForm.faqiName"
                placeholder="发起名称"
                :clearable="true"
                style="width: 150px"
              ></el-input>
            </el-form-item>
            <el-form-item label="被考核人">
              <el-input
                v-model="dataForm.ryName"
                placeholder="考核人"
                :clearable="true"
                style="width: 150px"
              ></el-input>
            </el-form-item>
            <el-form-item label="被考核人岗位">
              <el-input
                v-model="dataForm.userZw"
                placeholder="被考核人岗位"
                :clearable="true"
                style="width: 150px"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                icon="el-icon-search"
                type="primary"
                class="marginLeft"
                @click="getDataList()"
                >检索
              </el-button>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="24">
          <el-table
            ref="table"
            style="width: 100%; margin-top: 20px"
            :data="dataList"
            border
            v-loading="dataListLoading"
          >
            <el-table-column
              type="selection"
              width="55"
              header-align="center"
              align="center"
            ></el-table-column>
            <el-table-column
              type="index"
              width="80"
              header-align="center"
              align="center"
              label="序号"
            ></el-table-column>
            <el-table-column
              prop="faqiName"
              header-align="center"
              align="center"
              label="发起名称"
              min-width="200"
            >
            </el-table-column>
            <el-table-column
              prop="userName"
              header-align="center"
              align="center"
              min-width="120"
              label="被考核人编号"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="ryName"
              header-align="center"
              align="center"
              min-width="120"
              label="被考核人姓名"
              show-overflow-tooltip
            >
              <!-- <template slot-scope="scope">
                        <span
                            @click="checkDetails(scope.row)"
                            style="color: #0e258c; cursor: pointer"
                            >{{ scope.row.ryName }}</span
                        >
                        </template> -->
            </el-table-column>
            <el-table-column
              prop="userDeptName"
              header-align="center"
              align="center"
              min-width="120"
              label="被考核人单位"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="userZw"
              header-align="center"
              align="center"
              label="被考核人岗位"
              min-width="180"
              show-overflow-tooltip
            >
              <!-- v-if="showType == 1" -->
              <!-- <template slot="header">
                        <el-tooltip placement="top" content="点击切换至被考核人职级">
                            <span @click="switchBtn(2)">被考核人岗位</span>
                        </el-tooltip>
                        </template> -->
            </el-table-column>
          </el-table>
        </el-col>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSumbmit" v-loading.fullscreen.lock="fullscreenLoading">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPageForrwnd,
  copyRwDetails,
  rwDetailisflag,
} from "@/api/hetongrenwu/zhongdian/renwuchuangjian";
export default {
  data() {
    return {
      dataForm: {},
      dialogVisible: false,
      dataList: [],
      dataListLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      ndId: "",
      cjId: "",
      detaillist: [],
      recordId:"",
      fullscreenLoading:false,
    };
  },
  methods: {
    init(data, list) {
      this.dialogVisible = true;
      this.cjId = data.cjId;
      this.ndId = data.id;
      this.detaillist = list;
      this.getDataList();
    },
    getDataList() {
      this.dataListLoading = true;
      getPageForrwnd(
        Object.assign(
          {
            current: this.pageIndex,
            size: this.pageSize,
            id: this.cjId,
          },
          this.dataForm
        )
      ).then((res) => {
        this.dataList = res.data.data.records;
        this.totalPage = res.data.data.total;
        this.dataListLoading = false;
      });
    },
    //提交
    onSumbmit() {
      var data = this.$refs.table.selection;
      if (data.length == 0) {
        this.$message.warning("请选择复用的数据!");
        return false;
      }
      if (data.length > 1) {
        this.$message.warning("只能选择一条数据!");
        return false;
      }
      var detailCjids = [];
      if (data.length == 1) {
        var params = {
          id: data[0].id,
          cjId: this.cjId,
          ndId: this.ndId,
          recordId:data[0].recordId,
        };
        data.forEach((item) => {
          detailCjids.push(item.id);
        });
        var obj = {
          cjid: detailCjids,
          detaillist: this.detaillist,
        };
        rwDetailisflag(obj).then((res) => {
          var that = this;
          if (res.data.data) {
            this.$confirm(
              "任务名称取得情况相同，是否继续复用到其他任务？",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              }
            )
              .then(() => {
                that.fncopyRwDetails(params);
              })
              .catch(() => {});
          } else {
            that.fncopyRwDetails(params);
          }
        });
      }
    },
    fncopyRwDetails(params) {
      this.fullscreenLoading = true;
      copyRwDetails(params).then((res) => {
        if (res.data.code == 0) {
          this.$message.success("复用成功");
          this.fullscreenLoading = false;
          this.$emit("fuyongChild");
          this.close();
        }
      });
    },
    close() {
      this.dialogVisible = false;
      this.dataForm = {};
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
  },
};
</script>

<style>
</style>